<?php

/**
 * Establishes database connection
 *
 * PHP version 5
 *
 * LICENSE: This source file is subject to the MIT License, available
 * at http://www.opensource.org/licenses/mit-license.html
 *
 * @author     Jayson Schmidt <jayson@888mobileapps.com>
 * @copyright  2013 888MobileApps
 * @license    http://www.opensource.org/licenses/mit-license.html
 */

class DB_Connect {

	/*
	 * @var object A database object
	 */
	
	protected $db;
	
	/*
	 * Checks for a DB object of creates one if it isn't found
	 *
	 * @param object $dbo A database object
	 */
	
	protected function __construct($dbo = NULL) {
		if(is_object($dbo)) {
			$this->db = $dbo;
		}else {
			// For constants see /config/db-cred.inc.php
			$dsn = "mysql:host=".DB_HOST.";dbname=".DB_NAME;
			try{
				$this->db = new PDO($dsn, DB_USER, DB_PASS);
			}catch(Exception $e){
				die($e->getMessage());
			}
		}
	}
}

?>